/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.fh.itsbankomat.businesslogic.model;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author MeinLaptop
 */
@Entity
@Table(name = "KONTO")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Konto.findAll", query = "SELECT k FROM Konto k"),
    @NamedQuery(name = "Konto.findByIban", query = "SELECT k FROM Konto k WHERE k.kontoPK.iban = :iban"),
    @NamedQuery(name = "Konto.findByBic", query = "SELECT k FROM Konto k WHERE k.kontoPK.bic = :bic"),
    @NamedQuery(name = "Konto.findByKundeid", query = "SELECT k FROM Konto k WHERE k.kontoPK.kundeid = :kundeid"),
    @NamedQuery(name = "Konto.findBySaldo", query = "SELECT k FROM Konto k WHERE k.saldo = :saldo"),
    @NamedQuery(name = "Konto.findByUeberziehungsrahmen", query = "SELECT k FROM Konto k WHERE k.ueberziehungsrahmen = :ueberziehungsrahmen")})
public class Konto implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected KontoPK kontoPK;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "SALDO")
    private BigDecimal saldo;
    @Column(name = "UEBERZIEHUNGSRAHMEN")
    private BigDecimal ueberziehungsrahmen;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "konto")
    private Collection<Bankomatkarte> bankomatkarteCollection;
    @JoinColumn(name = "KUNDEID", referencedColumnName = "KUNDEID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Kunde kunde;
    @JoinColumn(name = "BIC", referencedColumnName = "BIC", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Kreditinstitut kreditinstitut;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "konto")
    private Collection<Buchungssatz> buchungssatzCollection;

    public Konto() {
    }

    public Konto(KontoPK kontoPK) {
        this.kontoPK = kontoPK;
    }

    public Konto(String iban, String bic, int kundeid) {
        this.kontoPK = new KontoPK(iban, bic, kundeid);
    }

    public KontoPK getKontoPK() {
        return kontoPK;
    }

    public void setKontoPK(KontoPK kontoPK) {
        this.kontoPK = kontoPK;
    }

    public BigDecimal getSaldo() {
        return saldo;
    }

    public void setSaldo(BigDecimal saldo) {
        this.saldo = saldo;
    }

    public BigDecimal getUeberziehungsrahmen() {
        return ueberziehungsrahmen;
    }

    public void setUeberziehungsrahmen(BigDecimal ueberziehungsrahmen) {
        this.ueberziehungsrahmen = ueberziehungsrahmen;
    }

    @XmlTransient
    public Collection<Bankomatkarte> getBankomatkarteCollection() {
        return bankomatkarteCollection;
    }

    public void setBankomatkarteCollection(Collection<Bankomatkarte> bankomatkarteCollection) {
        this.bankomatkarteCollection = bankomatkarteCollection;
    }

    public Kunde getKunde() {
        return kunde;
    }

    public void setKunde(Kunde kunde) {
        this.kunde = kunde;
    }

    public Kreditinstitut getKreditinstitut() {
        return kreditinstitut;
    }

    public void setKreditinstitut(Kreditinstitut kreditinstitut) {
        this.kreditinstitut = kreditinstitut;
    }

    @XmlTransient
    public Collection<Buchungssatz> getBuchungssatzCollection() {
        return buchungssatzCollection;
    }

    public void setBuchungssatzCollection(Collection<Buchungssatz> buchungssatzCollection) {
        this.buchungssatzCollection = buchungssatzCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (kontoPK != null ? kontoPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Konto)) {
            return false;
        }
        Konto other = (Konto) object;
        if ((this.kontoPK == null && other.kontoPK != null) || (this.kontoPK != null && !this.kontoPK.equals(other.kontoPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.fh.itsbankomat.businesslogic.model.Konto[ kontoPK=" + kontoPK + " ]";
    }
    
}
